package com.itsu.integration.service.impl;

import com.itsu.integration.factory.GetCountryResponse;
import com.itsu.integration.vo.Response;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 自定义返回类型，并重新包装返回对象
 *
 * @author suben
 * @date 2020/4/30 16:28
 */
@Service
public class BuildResponse {

    public Response build(Message message) {
        GetCountryResponse getCountryResponse = (GetCountryResponse) message.getPayload();

        //如果call ws 返回结果name为null且人口为-1说明ws系统查询不到数据或结果出错
        if (StringUtils.isEmpty(getCountryResponse.getCountry().getName()) && getCountryResponse.getCountry().getPopulation() == -1) {
            return new Response("not found", null);
        }
        return new Response("ok", getCountryResponse);
    }


}
